<?php 
namespace Admin\Controller;
use HDPHP\Library\Controller;
/**
 * 登陆控制器
 */
class LoginController extends Controller{
	/**
	 * 默认方法
	 */
	public function index(){
		if(IS_POST){
			//处理用户名
    		$username = htmlspecialchars($_POST['account']);
			//md5加密处理密码
			$password = md5($_POST['pwd']);
			//检测用户名是否存在
			$sql = "SELECT * FROM hd_admin WHERE username='{$username}'";
			$data =M()->query($sql);
//			z($data);
			$data =isset($data[0])?$data[0]:NULL;
//			z($data);
			if(!$data){
				$this->error('用户名不存在','./index.php?m=Admin&c=Login');
			}
			//检测密码是否正确
			if($data['passwd']!=$password){
				$this->error('密码错误','./index.php?m=Admin&c=Login');
			}
			$_SESSION['aname'] = $username;
			$aid=$data['aid'];
			$_SESSION['aid']=$data['aid'];
						//成功方法
			
		    $this->success('登陆成功',"./index.php?m=Admin&aid={$aid}");
		}
		$this->display();
	}
	
	public function code(){
		$code = new \HDPHP\Tool\Code;
		$code->show();
	}
	
	
}

